package com.ruoyi.crm.activity.controller;

import java.util.List;
import java.util.Map;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.crm.activity.domain.CrmActivity;
import com.ruoyi.crm.activity.service.ICrmActivityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * crm活动表Controller
 * 
 * @author ruoyi
 * @date 2021-09-06
 */
@RestController
@RequestMapping("/crm/activity")
public class CrmActivityController extends BaseController
{
    @Autowired
    private ICrmActivityService crmActivityService;

    /**
     * 查询crm活动表列表
     */
    @PreAuthorize("@ss.hasPermi('crm:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmActivity crmActivity)
    {
        List<CrmActivity> list = crmActivityService.selectCrmActivityList(crmActivity);
        return getDataTable(list);
    }

    /**
     * 快到期提醒
     */
    @PreAuthorize("@ss.hasPermi('crm:activity:list')")
    @GetMapping("/selDealtWith")
    public TableDataInfo selDealtWith()
    {
    	startPage();
        List<Map<String, Object>> list = crmActivityService.selDealtWith();
        return getDataTable(list);
    }

    /**
     * 导出crm活动表列表
     */
    @PreAuthorize("@ss.hasPermi('crm:activity:export')")
    @Log(title = "crm活动表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmActivity crmActivity)
    {
        List<CrmActivity> list = crmActivityService.selectCrmActivityList(crmActivity);
        ExcelUtil<CrmActivity> util = new ExcelUtil<CrmActivity>(CrmActivity.class);
        return util.exportExcel(list, "crm活动表数据");
    }

    /**
     * 获取crm活动表详细信息
     */
    @PreAuthorize("@ss.hasPermi('crm:activity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmActivityService.selectCrmActivityById(id));
    }

    /**
     * 新增crm活动表
     */
    @PreAuthorize("@ss.hasPermi('crm:activity:add')")
    @Log(title = "crm活动表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmActivity crmActivity)
    {
        return toAjax(crmActivityService.insertCrmActivity(crmActivity));
    }

    /**
     * 修改crm活动表
     */
    @PreAuthorize("@ss.hasPermi('crm:activity:edit')")
    @Log(title = "crm活动表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmActivity crmActivity)
    {
        return toAjax(crmActivityService.updateCrmActivity(crmActivity));
    }

    /**
     * 删除crm活动表
     */
    @PreAuthorize("@ss.hasPermi('crm:activity:remove')")
    @Log(title = "crm活动表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmActivityService.deleteCrmActivityByIds(ids));
    }
}
